import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/manager/xindong_hello_ctr.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/models/user/xindong_home_user.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/utils/xindong_text_util.dart';
import 'package:xindong/widgets/common/xindong_common_dot.dart';
import 'package:xindong/widgets/xindong_avatar.dart';

class XinDongFriendItemWidget extends StatelessWidget {
  final XinDongHomeUser model;

  const XinDongFriendItemWidget({Key? key, required this.model}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => XinDongPageSingleton.instance.jumpToSpace(model),
      behavior: HitTestBehavior.opaque,
      child: Container(
        height: 92,
        color: DZColors.cellColor,
        padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
        child: Row(
          children: [
            Stack(
              fit: StackFit.loose,
              clipBehavior: Clip.none,
              children: [
                XinDongAvatar(url: model.user_head, size: 72, radius: 10),
                if (model.is_online == 1)
                  Positioned(
                    top: -3,
                    right: -3,
                    child: XinDongCommonDot(color: DZColors.statusCorrectColor, size: 10),
                  ),
              ],
            ),
            const SizedBox(width: 10),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  SizedBox(
                    height: 22,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Flexible(
                          child: Text(
                            model.user_name ?? "",
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: const TextStyle(
                                color: DZColors.titleColor, fontSize: 16, fontWeight: FontWeight.w600, height: 1.2),
                          ),
                        ),
                        const SizedBox(width: 8),
                      ],
                    ),
                  ),
                  const SizedBox(height: 4),
                  Flexible(
                    child: Text(
                      "${model.user_age}岁${TextUtil.isEmpty(model.statureText) ? "" : " | ${model.statureText}"}${TextUtil.isEmpty(model.occupation) ? "" : ""
                          " | ${model.occupation}"}",
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: const TextStyle(fontSize: 14, color: DZColors.contentColor),
                    ),
                  ),
                  Flexible(
                    child: Text(
                      model.self_slogan ?? "",
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: const TextStyle(fontSize: 14, color: DZColors.contentColor),
                    ),
                  )
                ],
              ),
            ),
            GetBuilder<XinDongHelloCtr>(
              id: "${model.user_id}",
              builder: (controller) {
                return GestureDetector(
                  onTap: () => XinDongHelloCtr.to.onSayHelloUser(model),
                  behavior: HitTestBehavior.opaque,
                  child: ImageUtil.asset(
                    model.canSayHello == true ? AssetsRes.BUTTON_DASHAN : AssetsRes.BUTTON_SIXIN,
                    width: 60,
                    height: 30,
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}
